package com.itrencai.d13_thread.threadpoor;

import java.util.concurrent.Callable;

//1.定义一个任务类实现Colloble接口，应该声明线程任务执行完毕后的结果的数据类型

class MyCallable implements Callable<String>{
    private int n;
    public MyCallable(int n){
        this.n=n;
    }
    //2.重写call方法(线程任务方法)
    @Override
    public String call() throws Exception {
       int sum=0;
        for (int i = 1; i <=n; i++) {
            sum+=i;
        }
        return Thread.currentThread().getName()+"执行1-"+n+"的和，结果是："+sum;
    }
}




